﻿using System;
using System.Diagnostics;

namespace SmartHRMS.CustomExceptions.Infrastructure
{
    public class ApplicationException: System.Exception
	{
		public ApplicationException()
		{
			LogEvent("An unexpected error occurred.");
		}

		public ApplicationException(string message)
		{
			LogEvent(message);
		}

        public ApplicationException(string message, Exception innerException)
		{
			LogEvent(message);
			if (innerException != null)
			{
				LogEvent(innerException.Message);
			}
		}

		private void LogEvent(string message)
		{
			if (!EventLog.SourceExists("SmartHRMS"))
			{
                EventLog.CreateEventSource("SmartHRMS", "Application");
			}
            EventLog.WriteEntry("SmartHRMS", message, EventLogEntryType.Error);
		}
	}
}

